﻿using System;
using System.Collections.Generic;

namespace TaskBoardProject.TaskComparers
{
    /// <summary>
    /// Comparer by priority
    /// </summary>
    public class TaskPriorityComparer : IComparer <Task>
    {
        /// <summary>
        /// Compare two tasks by task priority
        /// </summary>
        /// <param name="firstTask">first task</param>
        /// <param name="secondTask">second task</param>
        /// <returns>result of comparing</returns>
        public int Compare(Task firstTask, Task secondTask)
        {
            // Check if parameters are null
            if (firstTask == null && secondTask == null)
                return 0;
            else if (secondTask == null)
                return 1;
            else if (firstTask == null)
                return -1;
            else
                try
                {
                    return (int) firstTask.TaskPriority - (int) secondTask.TaskPriority;
                }
                catch (InvalidCastException invalidCastExeException)
                {
                    throw new ArgumentException("Can't cast priority to int", 
                                                invalidCastExeException);
                }
        }
    }
}
